<template>
    <el-dialog v-if="dialogVisible" :close-on-click-modal='false' title="裂变需求" :visible.sync="dialogVisible" @close="resetForm('fissionClipHzRef')" width="400px">
        <el-form label-position="top" label-width="auto" size="medium" :hide-required-asterisk='true' :model="fissionClipHzForm" :rules="fissionClipHzRules" ref="fissionClipHzRef" v-loading="loading">
            <el-form-item label="裂变对象">
                <ul class="sche_info">
                    <li class="flexbox flexcenter flexbetween">
                        <span>品牌/产品</span>
                        <span class="sche_text">{{brand_name}} - {{product_name}}</span>
                    </li>
                    <li class="flexbox flexcenter flexbetween">
                        <span>编导</span>
                        <span class="sche_text">{{director_name}}</span>
                    </li>
                    <li class="flexbox flexcenter flexbetween">
                        <span>执行人</span>
                        <div class="sche_text">
                            {{executor.map(val=>{return val.nickname}).toString()}}
                            <!-- <span v-for="(item,index) in executor" :key="index">{{item.nickname}},</span> -->
                        </div>
                    </li>
                </ul>
            </el-form-item>
            <el-form-item label="裂变类型" prop="fission_type">
                <el-select v-model="fissionClipHzForm.fission_type" filterable placeholder="请选择裂变类型" style="width:100%">
                    <el-option label="修改" :value="1"></el-option>
                    <el-option label="调整" :value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="裂变原因" prop="fission_reason">
                <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="fissionClipHzForm.fission_reason">
                </el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="resetForm('fissionClipHzRef')" class="el-button-width" size="small">取 消</el-button>
            <el-button type="primary" @click="submitForm('fissionClipHzRef')" class="el-button-width" size="small" :disabled='disabled' :loading="disabled">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>
export default {
    name: "",
    data() {
        return {
            disabled: false,
            dialogVisible: false,
            brand_name:'',
            product_name:'',
            director_name:'',
            executor:'',
            fissionClipHzForm: {
                id: "",
                fission_type: "",
                fission_reason: "",
            },
            fissionClipHzRules: {
                fission_type: [
                    {
                        required: true,
                        message: "请选择裂变类型",
                        trigger: "blur",
                    },
                ],
                fission_reason: [
                    {
                        required: true,
                        message: "请输入裂变原因",
                        trigger: "blur",
                    },
                ],
            },
        };
    },

    created() {
        this.$bus.on("fissionClipHz", (value) => {
            this.dialogVisible = value.dialogVsb;
            this.fissionClipHzForm.id = value.id;
            this.brand_name = value.brand_name;
            this.product_name = value.product_name;
            this.director_name = value.director_name;
            this.executor = value.executor;
        });
    },
    beforeDestroy() {
        this.$bus.off("fissionClipHz");
    },
    methods: {
        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    this.disabled = true;
                    const { data: res } = await this.$http.post(
                        "adminapi/demandhz/clipFission",
                        this.fissionClipHzForm
                    );
                    if (res.code !== 200) {
                        this.disabled = false;
                        this.$message.error(res.msg);
                        return;
                    } else {
                        this.$message({
                            message: "裂变成功",
                            type: "success",
                        });
                        this.disabled = false;
                        this.resetForm(formName);
                        this.$parent.getDataList(this.$parent.setpage);
                    }
                } else {
                    this.disabled = false;
                    return false;
                }
            });
        },

        // 关闭重置表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dialogVisible = false;
        },
    },
};
</script>
<style scoped>
.sche_info {
    font-size: 14px;
    color: #616c85;
    background-color: rgba(165, 177, 209, 0.08);
    border-radius: 12px;
    padding: 12px;
}
.sche_info li {
    height: 36px;
}
.sche_text {
    color: #17233d;
}
</style>

